package servlet_test;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class ServletContext1 extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("我是POST");
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("我是GET");
        ServletContext context = getServletConfig().getServletContext();
        System.out.println("Username："+context.getInitParameter("username"));
        System.out.println("URL："+context.getInitParameter("url"));
        System.out.println("Context的路径："+context.getContextPath());
        System.out.println("工程绝对路径的整合："+context.getRealPath("/"));

        System.out.println("我是context1，要获得key1的值："+context.getAttribute("key1"));
    }
}
